import React, {Component} from 'react'

class ReactIF extends Component {
  render() {
    const {rif, children} = this.props
    if (children instanceof Array) {
      let resultChildren = children;
      // 如果是数组 就判断有没有  else 标记
      resultChildren = children.map(element => {
        if (rif) {
          return element.props.relse ? null : element
        } else {
          return element.props.relse ? element : null
        }
      }).filter(element => element)

      if (resultChildren.length === 1) {
        resultChildren = resultChildren[0]
      } else if (resultChildren.length === 0) {
        resultChildren = null
      }
      return resultChildren
    }
    return rif ? children : null
  }
}

export default ReactIF;
